<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JS Drum Kit</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="keys">
<div data-key="65" class="key ">
<kbd>A</kbd>
<span class="sound">CLAP</span>
</div>
<div data-key="83" class="key">
<kbd>S</kbd>
<span class="sound">HIHAT</span>
</div>
<div data-key="68" class="key">
<kbd>D</kbd>
<span class="sound">KICK</span>
</div>
<div data-key="70" class="key">
<kbd>F</kbd>
<span class="sound">OPENHAT</span>
</div>
<div data-key="71" class="key">
<kbd>G</kbd>
<span class="sound">BOOM</span>
</div>
<div data-key="72" class="key">
<kbd>H</kbd>
<span class="sound">RIDE</span>
</div>
<div data-key="74" class="key">
<kbd>J</kbd>
<span class="sound">SNARE</span>
</div>
<div data-key="75" class="key">
<kbd>K</kbd>
<span class="sound">TOM</span>
</div>
<div data-key="76" class="key">
<kbd>L</kbd>
<span class="sound">TINK</span>
</div>
</div>
  <audio data-key="65" src="sounds/clap.wav"></audio>
  <audio data-key="83" src="sounds/hihat.wav"></audio>
  <audio data-key="68" src="sounds/kick.wav"></audio>
  <audio data-key="70" src="sounds/openhat.wav"></audio>
  <audio data-key="71" src="sounds/boom.wav"></audio>
  <audio data-key="72" src="sounds/ride.wav"></audio>
  <audio data-key="74" src="sounds/snare.wav"></audio>
  <audio data-key="75" src="sounds/tom.wav"></audio>
  <audio data-key="76" src="sounds/tink.wav"></audio>
<script>
  function playSound(e) {
      const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
      const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
      if (!audio) return;

      key.classList.add('playing');
      audio.currentTime = 0;
      audio.play();
    }
	function stopTransition(e){
	if(e.propertyName="transform")
	e.target.classList.remove('playing');
	}
	const keys=Array.from(document.querySelectorAll('.key'));
	keys.forEach(key=>key.addEventListener('transitionend',stopTransition));
window.addEventListener('keydown', playSound);
</script>
</body>
</html>
